import { getToken,setToken,getUserInfo,setUserInfo,getAddress,setAddress } from '@/utils/storage'

export default {
	mutations: {
		updateRedirect(state,newRedirectObj){		// 修改重定向的页面路径
			state.redirect = newRedirectObj
			console.log(state.redirect,'user-store.js')
		},
		updateToken(state,newToken){
			state.token = newToken
			// 持久化数据至本地存储中
			setToken(state.token)
		},
		updateUserInfo(state,newUserInfo){	// 修改用户信息数据的处理函数
			state.userInfo = newUserInfo
			// 持久化数据至本地存储中
			setUserInfo(state.userInfo)
		},
		updateAddress(state,newAddress){		// 修改 address 数据
			state.address = newAddress
			// 实现持久化本地存储
			setAddress(state.address)
		}
	},
	getters: {
		addstr(state){
			if(!state.address.provinceName){
				return
			}
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
		}
	},
	state(){
		return {
			redirect: null,				// 重定向的页面路径
			address: getAddress(),
			token: getToken(),
			userInfo: getUserInfo()
		}
	},
	namespaced: true		// 开启命名空间模式
}